// 页面路径：store/index.js 
import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex); //vue的插件机制

//Vuex.Store 构造器选项
const store = new Vuex.Store({
    // 全局数据
    state: { //存放状态
        "parentId": 0,
        "navCurrent": 1,
        "tabCurrent": 3,
        "categoryId": 12,
        "productId": 1,
        "querySearch": true,
        "middleReveal": true,
        "categoryReveal": true,
        "shopsReveal": false,
        "shopDetailReveal": false,
        "yinxiao": []
    },
    // 全局的计算属性
    getters: {

    },
    // 修改数据的方法
    mutations: {
        updateNavCurrent(state, newValue) {
            state.navCurrent = newValue;
        },
        updateTabCurrent(state, newValue) {
            state.tabCurrent = newValue;
        },
        updateCategoryId(state, newValue) {
            state.categoryId = newValue;
        },
        updateProductId(state, newValue) {
            state.productId = newValue;
        },
        updateCategoryAndShopsReveals(state, category) {
            if (typeof category === 'boolean') {
                if (state.categoryReveal != category) {
                    state.categoryReveal = category;
                    state.shopsReveal = !category;
                }
            }
        },
        updateMiddleOrShopDetailReveal(state, middle) {
            if (typeof middle === 'boolean') {
                if (state.middleReveal != middle) {
                    this.tabTemp = this.tabCurrent;
                    state.middleReveal = middle;
                    state.querySearch = middle;
                    state.shopDetailReveal = !middle;
                }
            }
        },
        updateYinXiao(state, newValue) {
            state.yinxiao = newValue;
        }
    },
    // 全局异步操作的方法
    actions: {

    }
})
export default store